﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data.Objects;
using OnlineBookStore.OBSModel;
using OnlineBookStore.IDAL;

namespace OnlineBookStore.OBSBLL
{
    /// <summary>
    /// 业务逻辑层的User类，用于操作用户
    /// </summary>
    public class UserManage
    {
        /// <summary>
        /// 通过数据访问工厂（DALFactory）创建一个实例
        /// </summary>
        private readonly IUser dal = OnlineBookStore.DALFactory.DataAccess.CreateUser();
        /// <summary>
        /// 通过用户名查找用户实体
        /// </summary>
        /// <param name="userName">用户名</param>
        /// <returns>用户实体</returns>
        public UserInfo GetUserByUsername(string userName)
        {
            if (string.IsNullOrEmpty(userName))
                return null;
            return dal.GetUserByUsername(userName);
        }
        /// <summary>
        /// 返回所有用户
        /// </summary>
        /// <returns>用户实体集</returns>
        public IList<UserInfo> GetAllUsers()
        {
            return dal.GetAllUsers();
        }
        /// <summary>
        /// 通过用户角色查找用户集
        /// </summary>
        /// <param name="roleName">用户所在角色的角色名</param>
        /// <returns>返回结果的用户集</returns>
        public IList<UserInfo> GetUsersByRole(string roleName)
        {
            if (string.IsNullOrEmpty(roleName))
                return null;
            return dal.GetUsersByRole(roleName);

        //}


    }
}
